﻿using FySystem.Converter;
using FySystem.FyAppConfig;
using FySystem.Secure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FyCaches.Core.Services
{
    class AuthService
    {
        private static List<string> _md5 = new List<string>();

        /// <summary>
        /// 初始化用户认证
        /// </summary>
        internal static void Init()
        {
            try
            {
                string user = FyAppConfigManager.Appconfigs["user"];
                string pwd = FyAppConfigManager.Appconfigs["pwd"];

                byte[] md5 = MD5.MD5EncryptB(user + pwd);
                _md5.Add(NumberConversion.BytesToHexString(md5, 0, md5.Length, false));
            }
            catch (Exception ex)
            {
                FyLogContext.Write(ex.Message);
            }
        }

        internal static bool AuthUser(string authMd5)
        {
            return _md5.Contains(authMd5);
        }
    }
}
